﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace NoLimit_Brwoser
{
    public partial class FrmNewWin : Form
    {
        public FrmNewWin(string url)
        {
            InitializeComponent();
            webBrowser1.Navigate(url);
        }

        //解除js限制
        private void AddJS(string js)
        {
            HtmlElement ele = webBrowser1.Document.CreateElement("script");
            ele.SetAttribute("type", "text/javascript");
            ele.SetAttribute("text", js);
            webBrowser1.Document.Body.AppendChild(ele);
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            AddJS("function document.onselectstart(){return true;}");
            AddJS("function document.oncontextmenu() { return true; }");
            AddJS("function document.onkeydown() {if (event.ctrlKey && event.keyCode == 67) {event.returnValue = true; }}");
            AddJS("function document.oncopy(){return true;}");
            AddJS("function document.onpaste(){return true;}");
            try
            {

                HtmlElement ele = webBrowser1.Document.GetElementsByTagName("body")[0];
                ele.SetAttribute("onpaste", "return true");
            }
            catch (System.Exception ex)
            {

            }

            this.Text = ((WebBrowser)sender).DocumentTitle;
        }

        private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
        }
    }
}
